/**
 * @program: LeetCode
 * @description: LeetCode : 27. 移除元素
 * @author: WXY
 * @create: 2023-01-13 10:35
 * @Version 1.0
 **/
public class Num027_removeElement {
    public static int removeElement1(int[] nums, int val) {
        if (nums.length == 0) return 0;
        int slowIndex = 0;
        for (int fastIndex = 0; fastIndex < nums.length; fastIndex++) {
            if (val != nums[fastIndex]) {
                nums[slowIndex++] = nums[fastIndex];
            }
        }
        return slowIndex;
    }

    public static int removeElement(int[] arr, int val) {
        if (arr.length == 0)return 0;
        int slow = 0;
        for (int fast = 0; fast < arr.length; fast++) {
            if (arr[fast] != 0) {
                arr[slow++] = arr[fast];
            }
        }
        return slow;
    }

    private static void printArr(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + " ");
        }
        System.out.println();
    }

    public static void main(String[] args) {
        int[] arr = {2, 5, 4, 6, 5, 4, 4};
        removeElement(arr, 5);

    }
}
